From d07231cb7aad19b94f52e9a8af768a6c39919e6d Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 21 Jan 2011 13:36:27 -0600 Subject: [PATCH] bgo#626336 - Don't assume that GtkButton is activated only when a keyboard event is available Buttons may also be activated at any time from gtk_widget_activate() or related functions. In that case, just do the 'show the button as pushed for a short amount of time' trick, but don't actually try to grab the keyboard device. Signed-off-by: Federico Mena Quintero --- gtk/gtkbutton.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 3d3bd8630c..baad6ebf29 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -1860,20 +1860,24 @@ gtk_real_button_activate (GtkButton *button) if (device && gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD) device = gdk_device_get_associated_device (device); - g_return_if_fail (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD); - if (gtk_widget_get_realized (widget) && !priv->activate_timeout) { time = gtk_get_current_event_time (); - if (gdk_device_grab (device, priv->event_window, - GDK_OWNERSHIP_WINDOW, TRUE, - GDK_KEY_PRESS | GDK_KEY_RELEASE, - NULL, time) == GDK_GRAB_SUCCESS) - { - gtk_device_grab_add (widget, device, TRUE); - priv->grab_keyboard = device; - priv->grab_time = time; + /* bgo#626336 - Only grab if we have a device (from an event), not if we + * were activated programmatically when no event is available. + */ + if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) + { + if (gdk_device_grab (device, priv->event_window, + GDK_OWNERSHIP_WINDOW, TRUE, + GDK_KEY_PRESS | GDK_KEY_RELEASE, + NULL, time) == GDK_GRAB_SUCCESS) + { + gtk_device_grab_add (widget, device, TRUE); + priv->grab_keyboard = device; + priv->grab_time = time; + } } priv->activate_timeout = gdk_threads_add_timeout (ACTIVATE_TIMEOUT, -- 2.30.2